package Aula19;

public class Rotacoes {
	
	public void zigRight(No no) {
		
        No parent = no.parent;
        No t2 = no.right;
		No t3 = parent.right;
		no.parent = parent.parent;
		no.right = parent;
		parent.parent = no;
		parent.left = t2;
		if(t2 != null)
			t2.parent = parent;
		parent.right = t3;
		if(t3 != null)
			t3.parent = parent;
		
    }
   
    public void zigLeft(No no) {
    	No parent = no.parent;
    	No t2 = no.left;
		No t3 = no.right;
		no.parent = parent.parent;
		no.left = parent;
		no.right = t3;
		if(t3 != null)
			t3.parent = no;
		parent.parent = no;
		parent.right = t2;
		if(t2 != null)
			t2.parent = parent;
    }
   
    public void zigZigRight(No no) {
    	No parent = no.parent;
    	No vo = parent.parent;
    	No t2 = no.right;
		No t3 = parent.right;
		No t4 = vo.right;
		no.parent = vo.parent;
		no.right = parent;
		parent.parent = no;
		parent.left = t2;
		if(t2 != null)
			t2.parent = parent;
		parent.right = vo;
		vo.parent = parent;
		vo.left = t3;
		if(t3 != null)
			t3.parent = vo;
		vo.right = t4;
		if(t4 != null)
			t4.parent = vo;
    }

    public void zigZigLeft(No no) {
    	No parent = no.parent;
    	No vo = parent.parent;
    	No t2 = parent.left;
		No t3 = no.left;
		No t4 = no.right;
		no.parent = vo.parent;
		no.left = parent;
		no.right = t4;
		if(t4 != null)
			t4.parent = no;
		parent.parent = no;
		parent.left = vo;
		parent.right = t3;
		if(t3 != null)
			t3.parent = parent;
		vo.parent = parent;
		vo.right = t2;
		if(t2 != null)
			t2.parent = vo;
    }

    public void zigZagLeft(No no) {
    	No parent = no.parent;
    	No vo = parent.parent;
    	No t2 = no.left;
		No t3 = no.right;
		parent.parent = no;
		parent.right = t2;
		if(t2 != null)
			t2.parent = parent;
		no.parent = vo.parent;
		no.left = parent;
		no.right = vo;
		vo.parent = no;
		vo.left = t3;
		if(t3 != null)
			t3.parent = vo;
    }
    
    public void zigZagRight(No no){
      	No parent = no.parent;
    	No vo = parent.parent;
    	No t2 = no.left;
		No t3 = no.right;
		No t4 = parent.right;
		parent.parent = no;
		parent.left = t3;
		if(t3 != null)
			t3.parent = parent;
		parent.right = t4;
		if(t4 != null)
			t4.parent = parent;			
		no.parent = vo.parent;
		no.left = vo;
		no.right = parent;
		vo.parent = no;
		vo.right = t2;
		if(t2 != null)
			t2.parent = vo;
    }

}
